package com.smedi.ismedi.notification.core.application.query.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.notification.core.application.query.MailTemplateQueryService;
import com.smedi.ismedi.notification.core.application.query.vo.MailTemplateVo;
import com.smedi.ismedi.notification.core.application.query.vo.SmsTemplateVo;
import com.smedi.ismedi.notification.core.domain.aggregatemodel.MailTemplate;
import com.smedi.ismedi.notification.core.domain.aggregatemodel.SmsTemplate;
import com.smedi.ismedi.notification.core.domain.service.MailTemplateDomainService;
import com.smedi.ismedi.notification.core.domain.service.SmsTemplateDomainService;
import com.smedi.ismedi.notification.core.infrastructure.enumerate.SmsTemplateStatusEnum;
import com.smedi.ismedi.notification.core.port.adapter.persistence.mybatis.mapper.MailTemplateMapper;
import com.smedi.ismedi.notification.core.port.adapter.persistence.mybatis.mapper.SmsTemplateMapper;
import com.smedi.ismedi.notification.core.port.service.SmsClientRemoteApiService;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import com.tencentcloudapi.sms.v20190711.models.DescribeSmsTemplateListResponse;
import com.tencentcloudapi.sms.v20190711.models.DescribeTemplateListStatus;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @className: MailTemplateQueryServiceImpl
 * @Description: TODO
 * @version: v1.0.0
 * @author: wzx
 * @date: 2022/11/23 13:19
 */

@Slf4j
@Service
@AllArgsConstructor
public class MailTemplateQueryServiceImpl implements MailTemplateQueryService {

    private final MailTemplateMapper mailTemplateMapper;

    private final MailTemplateDomainService mailTemplateDomainService;

    private final DozerUtil dozerUtil;

    @Override
    public IPage getMailTemplatePaginationByTemplateName(Long offset, Long pageSize, String templateName) {
        Page<MailTemplateVo> page = new Page<>(offset, pageSize);
        page.addOrder(new OrderItem().descs("id"));

        return mailTemplateMapper.selectInternalAssignmentVoPagination(page, templateName);
    }

    @Override
    public MailTemplateVo getMailTemplateByMailTemplateId(Long mailTemplateId) {
        MailTemplate basic = mailTemplateDomainService.queryTemplateByMailTemplateId(mailTemplateId);
        return dozerUtil.convertor(basic, MailTemplateVo.class);
    }
}